<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
	<meta name="viewport" content="user-scalable=no,viewport-fit=cover" />
	<link href="./css/baseCss.css" rel="stylesheet" type="text/css"/>
	<link href="./base/layer.css" rel="stylesheet" type="text/css"/>
	<!-- <link href="./base/articlecon.css" rel="stylesheet" type="text/css"/> -->
	<link href="./base/base2.css" rel="stylesheet" type="text/css"/>
	<link rel="stylesheet" type="text/css" href="./css/swiper-3.4.0.min.css">
	<script type="text/javascript" src="./base/rem.js"></script>
	<script type="text/javascript" src="./base/iscroll.js"></script>
	<link rel="stylesheet" type="text/css" href="./css/index.css">

	<style type="text/css">
		
		
	</style>
	<title>首页搜索</title>
</head>
<body>
	<!-- <div id="container"></div> -->
	<div class="con">
		<div class="search">
			<div class="search-include"><img src="./img/search_01.png" onclick="searchRestaurant(0,this);"><input type="text" placeholder="你想吃点什么？"></div>
		</div>

		<div class="everyDay">
			<ul>
				<li class="everyDay-li" onclick="window.location.href='./detail.html'">
                	<div class="everyDay-img"><img src="./img/neet_02.png"></div>
                	<div class="everyDay-bar">
                	    <div>
                	        <span class="everyDay-title">小木屋韩式烧烤</span>
                	        <img class="everyDay-more" src="./img/dot_01.png">
                	    </div>
                	    <div class="everyDay-star">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	    </div>
                	    <div class="everyDay-detail">
                	        <div>起送￥<span>16</span></div>
                	        <div>配送费<span class="shipFee">3</span>元</div>
                	        <div><span class="everyDay-min">53分钟</span><span class="everyDay-shu">|</span><span>1.6km</span></div>
                	    </div>
                	    <div></div>
                	    <div class="everyDay-support">支持自取</div>
                	    <div class="everyDay-prefer">
                	        <img src="./img/pre_01.png">
                	        <span>满25减4;</span><span>满35减9;</span><span>满65减13</span>
                	    </div>
                	</div>
            	</li>
            	<li class="everyDay-li" onclick="window.location.href='./detail.html'">
                	<div class="everyDay-img"><img src="./img/neet_02.png"></div>
                	<div class="everyDay-bar">
                	    <div>
                	        <span class="everyDay-title">小木屋韩式烧烤</span>
                	        <img class="everyDay-more" src="./img/dot_01.png">
                	    </div>
                	    <div class="everyDay-star">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	    </div>
                	    <div class="everyDay-detail">
                	        <div>起送￥<span>16</span></div>
                	        <div>配送费<span class="shipFee">3</span>元</div>
                	        <div><span class="everyDay-min">53分钟</span><span class="everyDay-shu">|</span><span>1.6km</span></div>
                	    </div>
                	    <div></div>
                	    <div class="everyDay-support">支持自取</div>
                	    <div class="everyDay-prefer">
                	        <img src="./img/pre_01.png">
                	        <span>满25减4;</span><span>满35减9;</span><span>满65减13</span>
                	    </div>
                	</div>
            	</li>
            	<li class="everyDay-li" onclick="window.location.href='./detail.html'">
                	<div class="everyDay-img"><img src="./img/neet_02.png"></div>
                	<div class="everyDay-bar">
                	    <div>
                	        <span class="everyDay-title">小木屋韩式烧烤</span>
                	        <img class="everyDay-more" src="./img/dot_01.png">
                	    </div>
                	    <div class="everyDay-star">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	        <img src="./img/start.png">
                	    </div>
                	    <div class="everyDay-detail">
                	        <div>起送￥<span>16</span></div>
                	        <div>配送费<span class="shipFee">3</span>元</div>
                	        <div><span class="everyDay-min">53分钟</span><span class="everyDay-shu">|</span><span>1.6km</span></div>
                	    </div>
                	    <div></div>
                	    <div class="everyDay-support">支持自取</div>
                	    <div class="everyDay-prefer">
                	        <img src="./img/pre_01.png">
                	        <span>满25减4;</span><span>满35减9;</span><span>满65减13</span>
                	    </div>
                	</div>
            	</li>
			</ul>

			
		</div>
	</div>

</body>

<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/httpUnit.js"></script>
<script type="text/javascript" src="./js/constants.js"></script>
<script type="text/javascript">
	searchRestaurant(0);
	function searchRestaurant(page,that,refresh){
		if(page==0){

		}else{
			page = Math.ceil($(".everyDay ul > li").length/10);
		}

		if(that==undefined||that==null||that==""){
			var Request = new Object();
			Request = GetRequest();
			var nameOrCname = decodeURI(Request['nameOrCname']);
		}else{
			var nameOrCname = $(that).siblings("input").val();
		}

		
		var size = 10;
		var sort = "";
		var obj = JSON.stringify({
			"nameOrCname": nameOrCname,
		});
	
		httpHelperpost("/api/restaurants/searchRestaurant?page="+page+"&size="+size, obj, function(isSuccess, data) {
	        if (isSuccess == true) {
	            var response = data.responseText;
	            var value = JSON.parse(response);
	    			
	   			// console.log(response);
	
	            if(value.code == 0){
	             	console.log("查询成功");

	             	var liHtml = "";
            		var activity = new Array();
            		var activityHtml = "";
            		for(var i=0;i<value.data.length;i++){
            		    activityHtml = "";
            		    if(value.data[i].fullReduceActivity!=null){
            		        activity = value.data[i].fullReduceActivity.split(",");
            		        
            		        for(var j=0;j<activity.length-1;j++){
            		            activityHtml += "<span>"+activity[j]+"</span>";
            		        }
            		    }
            		    
            		    liHtml += "<li class='everyDay-li' onclick=window.location.href='./detail.html?id="+value.data[i].id+"'>"
            		            +"<div class='everyDay-img'><img src="+value.data[i].icon+"></div>"
            		            +"<div class='everyDay-bar'>"
            		            +"<div>"
            		            +"<span class='everyDay-title'>"+value.data[i].name+"</span>"
            		            +"<img class='everyDay-more' src='./img/dot_01.png'>"
            		            +"</div>"
            		            +"<div class='everyDay-star'>";
            		            for(var j=0,len=Math.round(levelisNull(value.data[i].evaluationLevel));j<len;j++){
                                	liHtml+="<img src='./img/start.png'>";
                            	}
            		    liHtml += "</div>"
            		            +"<div class='everyDay-detail'>"
            		            +"<div>起送￥<span>"+value.data[i].limitPrice+"</span></div>"
            		            +"<div>配送费<span class='shipFee'>"+value.data[i].dispatchPrice+"</span>元</div>"
            		            +"<div><span class='everyDay-min'>53分钟</span><span class='everyDay-shu'>|</span><span>1.6km</span></div>"
            		            +"</div>"
            		            +"<div></div>"
            		            +"<div class='everyDay-support'>支持自取</div>"
            		            +"<div class='everyDay-prefer'>"
            		            +"<img src='./img/pre_01.png'>"
            		            +"<span class='prefer-inc'>"+activityHtml+"</span>"
            		            +"</div></div></li>";
            		    }
            		if(refresh==true){
            			$(".everyDay ul").append(liHtml);
            		}else{
            			$(".everyDay ul").html(liHtml);
            		}
            		
	             	if(value.data==""){

	             	}else{
	             		dropRefresh();
	             	}
	             	
	            }else if(value.code==401){
	            	alert(value.message);
	            	window.location.href='./index.html';
	            }else{
	            	alert(value.message);
	             	console.log("查询失败");
	            }
	        }else {}
	    });
	}

	//下拉刷新
    function dropRefresh(){
    	var index = 0;
    	var lastNumber = 0;
    	$(window).scroll(function() {
			var scrollTop = $(document).scrollTop();//滚动条距离页面顶部距离
			var offsetHeight = $(document).height();//当前页面高度(包括滚动页面)
			var clientHeight = $(this).height();//当前页面高度(不包括滚动页面)
			var bottomHeight = scrollTop-(offsetHeight-clientHeight);
			
			if(bottomHeight>-1&&bottomHeight<1){
				searchRestaurant(null,null,true);
				
				$(window).unbind("scroll");		
			}
		});
    }

    function levelisNull(value){
        if(value==null||value==undefined){
            value = 0;
        }
        return value;
    }
		

	//获取url中"?"符后的字串
	function GetRequest() {
	    var url = location.search; //获取url中"?"符后的字串   
	    
	    var theRequest = new Object();
	    if (url.indexOf("?") != -1) {
	      var str = url.substr(1);
	      
	      strs = str.split("&");
	      
	      for (var i = 0; i < strs.length; i++) {
	        
	        theRequest[strs[i].split("=")[0]] = strs[i]
	            .split("=")[1];
	      }
	    }
	    return theRequest;
	}
</script>

</html>